use data_encoding::HEXLOWER;
use ring::digest::{Context, SHA1_FOR_LEGACY_USE_ONLY, SHA256, SHA512};

/// sha1加密
pub fn sha1<D: AsRef<[u8]>>(data: D) -> String {
    let mut context = Context::new(&SHA1_FOR_LEGACY_USE_ONLY);
    context.update(data.as_ref());
    let digest = context.finish();
    HEXLOWER.encode(digest.as_ref())
}

/// sha256加密
pub fn sha256<D: AsRef<[u8]>>(data: D) -> String {
    let mut context = Context::new(&SHA256);
    context.update(data.as_ref());
    let digest = context.finish();
    HEXLOWER.encode(digest.as_ref())
}

/// sha512加密
pub fn sha512<D: AsRef<[u8]>>(data: D) -> String {
    let mut context = Context::new(&SHA512);
    context.update(data.as_ref());
    let digest = context.finish();
    HEXLOWER.encode(digest.as_ref())
}